﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using Dapper;
using System.Data;
namespace ChuangDu_Spirit_QGB_DAL
{
    public partial class BaseDAL<T> where T :class,new() 
    {   /// <summary>
        /// 连接数据库
        /// </summary>
        private string ConnectStr = ConfigurationManager.ConnectionStrings["DbCoon"].ToString();
        /// <summary>
        /// 添加数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Add(T t)
        {
            using (IDbConnection coon = new SqlConnection(ConnectStr))
            {
                return coon.Insert(t) == null ? 0 : 1;  //0为添加失败   1位添加成功
            }
        }
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Delete(T t)
        {
            using (IDbConnection coon = new SqlConnection(ConnectStr))
            {
                return coon.Delete(t);
            }
        }
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public int Update(T t)
        {
            using (IDbConnection coon = new SqlConnection(ConnectStr))
            {
                return coon.Update(t);
            }
        }
        /// <summary>
        /// 显示全部数据
        /// </summary>
        /// <returns></returns>
        public IEnumerable<T> show()
        {
            using (IDbConnection coon = new SqlConnection(ConnectStr))
            {   
                return coon.GetList<T>();
            }
        }
        

    }
}
